#import "dfhgwhruebvhrheysecurityinjure.h"
@interface dfhgwhruebvhrheysecurityinjure ()<UITextFieldDelegate>
@property (nonatomic, strong) UITextField *input;
@end
@implementation dfhgwhruebvhrheysecurityinjure {
	void(^_start)(UITextField *inputTextField);
	void(^_finish)(UITextField *inputTextField);
	void(^_change)(UITextField *inputTextField);
	void(^_click)(dfhgwhruebvhrheysecurityinjure *clickView);
}
- (void)awakeFromNib {
	[super awakeFromNib];
	[self setUI];
}
- (void)setUI {
	self.layer.cornerRadius = 10;
	self.layer.borderWidth = 0.5;
	self.layer.masksToBounds = YES;
	self.input = (UITextField *)[self viewWithTag:100];
	self.input.textColor = @"#3B414B".dhgfywegwygeydwlearneddesignate;
	self.input.delegate = self;
	self.layer.borderColor = @"#CCCCCC".dhgfywegwygeydwlearneddesignate.CGColor;
	[self setType:self.type];
}
- (void)setType:(int)type {
	_type = type;
	if (self.type == 0) {
		self.input.enabled = YES;
		self.input.placeholder = @"Please fill in";
		[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(inputTextHasChange:) name:UITextFieldTextDidChangeNotification object:nil];
	}else {
		self.input.enabled = NO;
		self.input.placeholder = @"Please select";
		UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
		[tap addTarget:self action:@selector(tapGestureAction)];
		[self addGestureRecognizer:tap];
	}
}
- (void)bindContent:(NSString *)content {
	self.input.text = content;
}
- (BOOL)areadFilled {
	return self.input.text.length != 0;
}
- (void)setKeyboardType:(UIKeyboardType)keyboardType {
	self.input.keyboardType = keyboardType;
}
- (void)setCanInteractive:(BOOL)canInteractive {
	_canInteractive = canInteractive;
	self.userInteractionEnabled = canInteractive;
	if (canInteractive) {
		self.input.textColor = @"#3B414B".dhgfywegwygeydwlearneddesignate;
	}else {
		self.input.textColor = @"#7E7E7E".dhgfywegwygeydwlearneddesignate;
	}
}
- (void)setError:(BOOL)error {
	if (error) {
		if (self.input.text.length) {
			self.input.textColor = @"#FB3314".dhgfywegwygeydwlearneddesignate;
		}else {
			NSMutableAttributedString *matt = [[NSMutableAttributedString alloc] initWithString:self.input.placeholder];
			[matt addAttributes:@{NSForegroundColorAttributeName: @"#FB3314".dhgfywegwygeydwlearneddesignate} range:NSMakeRange(0, matt.length)];
			self.input.attributedPlaceholder = matt;
		}
	}else {
		if (self.input.text.length) {
			self.input.textColor = @"#3B414B".dhgfywegwygeydwlearneddesignate;
		}else {
			NSMutableAttributedString *matt = [[NSMutableAttributedString alloc] initWithString:self.input.placeholder];
			[matt addAttributes:@{NSForegroundColorAttributeName: @"#CCCCCC".dhgfywegwygeydwlearneddesignate} range:NSMakeRange(0, matt.length)];
			self.input.attributedPlaceholder = matt;
		}
	}
}
- (void)inputTextViewClick:(void(^)(dfhgwhruebvhrheysecurityinjure *clickView))click {
	_click = click;
}
- (void)inputTextChanged:(void(^)(UITextField *inputTextField))change {
	_change = change;
}
- (void)tapGestureAction {
	if (_click) {
		_click(self);
	}
}
- (void)inputStart:(void(^)(UITextField *inputTextField))completion {
	_start = completion;
}
- (void)inputFinish:(void(^)(UITextField *inputTextField))completion {
	_finish = completion;
}
- (void)inputTextHasChange:(NSNotification *)not {
	UITextField *textfiled = (UITextField *)not.object;
	if (![textfiled.superview isKindOfClass:[dfhgwhruebvhrheysecurityinjure class]]) return;
	dfhgwhruebvhrheysecurityinjure *sub = (dfhgwhruebvhrheysecurityinjure *)textfiled.superview;
	if (sub.contentType == dhgfywegwygeydwbeforehandversion) {
		NSString *phone = textfiled.text;
		if ([phone hasPrefix:@"0"]) {
			if (phone.length >= 11) {
				textfiled.text = [phone substringToIndex:11];
			}
		}else {
			if (phone.length >= 10) {
				textfiled.text = [phone substringToIndex:10];
			}
		}
		if (_change) {
			_change(textfiled);
		}
	}else {
		if (sub.contentType == dhgfywegwygeydwversionvictim) {
			if (textfiled.text.length > 16) {
				textfiled.text = [textfiled.text substringToIndex:16];
			}
			if (_change) {
				_change(textfiled);
			}
		}else {
			if (sub.length != 0) {
				if (textfiled.text.length >= sub.length) {
					textfiled.text = [textfiled.text substringToIndex:sub.length];
					[textfiled resignFirstResponder];
				}
				if (_change) {
					_change(textfiled);
				}
			}else {
				if (_change) {
					_change(textfiled);
				}
			}
		}
	}
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	if (self.contentType != dhgfywegwygeydwcollapsedefinitely) {
		return YES;
	}
	if (_finish) {
		[textField resignFirstResponder];
		_finish(textField);
	}
	return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
	if (self.contentType == dhgfywegwygeydwcollapsedefinitely) {
		return;
	}
	if (_finish) {
		_finish(textField);
	}
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
	if (_start) {
		_start(textField);
	}
	return YES;
}
@end
